package main

import (
	"GORM_Demo04/part08/MyPojo"
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

/*	常用方法

	【6】Where:加入指定条件：
		具体条件为：=,like,in,and,between....
	【7】Select：筛选查询出来的字段
*/

func main() {
	db, err := gorm.Open("mysql", "root:123456@tcp(192.168.11.189:3306)/lztest?charset=utf8&parseTime=True&loc=Local")

	if err != nil {
		panic(err)
	}
	defer db.Close()

	db.LogMode(true)

	/*【6】Where:加入指定条件：
	具体条件为：=,like,in,and,between....
	【7】Select：筛选查询出来的字段*/

	//【6】Where:加入指定条件：
	//	具体条件为：=,like,in,and,between....

	//var user MyPojo.User
	/*	//SELECT * FROM `users`  WHERE (uid = 1)
		db.Where("uid = ?", 1).Find(&user)*/

	//SELECT * FROM `users`  WHERE (u_name LIKE '%李%' )
	/*	var user []MyPojo.User
		db.Where("u_name like ? ", "%"+"张"+"%").Find(&user)*/

	/*	var user []MyPojo.User
		//SELECT * FROM `users`  WHERE (uid in (1,2))
		db.Where("uid in (?)", []int{1, 2}).Find(&user)
	*/

	/*	var user []MyPojo.User
		// SELECT * FROM `users`  WHERE (uid between 1 and 2)
		db.Where("uid between ? and ?", 1, 2).Find(&user)*/

	//【7】Select：筛选查询出来的字段
	var user MyPojo.User
	//SELECT uid,u_name FROM `users`  WHERE (uid = 1)
	db.Select("uid,u_name").Where("uid = ?", 1).Find(&user)

	fmt.Println(user)
}
